/*
 *	Copyright (c) 2013, Yulong Information Technologies
 *	All rights reserved.
 *  
 *  @Project: bbs
 *  @author: Robot
 *	@email: feng88724@126.com
 */
package com.wangyong.bbs.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import org.apache.commons.lang3.StringUtils;

/**
 * @author Robot
 * @weibo http://weibo.com/feng88724
 * @date Mar 7, 2013	
 */
public class UserDao {
	
	/**
	 * 验证用户名密码是否正确
	 * @param name
	 * @param password
	 * @return
	 * @throws Exception 
	 */
	public static boolean isUserValid(String name, String password) throws Exception {
		if(StringUtils.isEmpty(name) || StringUtils.isEmpty(password)) {
			return false;
		}
		String sql = String.format("select * from user where name = '%s' and password = '%s' limit 1", name, password);
		System.out.println(sql);
		boolean result = false;
		Connection conn = DbUtil.getConnection();
		PreparedStatement stat = conn.prepareStatement(sql);
		ResultSet set = stat.executeQuery();
		while(set.next()) {
			result = true;
			break;
		}
		return result;
	}
}
